package smlab.astar
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	/**
	 * astar 测试类主文件
	 * @author simon
	 * 
	 */
	[SWF(width=960,height=560)]
	public class SimonMapDemo extends Sprite
	{
		private var mapURL:String="../resource/astar_map.swf";
		private var mapModel:MapModel;
		private var p:Actor;
		private var walkAction:WalkAction;
		
		public function SimonMapDemo()
		{
			walkAction=new WalkAction;
			p=new Actor();
			p.direction=Direction.DOWN;
			mapModel=new MapModel();
			AStar.init(mapModel);
			mapModel.addEventListener(Event.COMPLETE,onMapLoaded);
			mapModel.addEventListener(Event.INIT,onMapInit);
			mapModel.loadMap(mapURL);
		}
		
		private function onMapLoaded(e:Event):void
		{
			addChild(mapModel.root);
		}
		
		private function onMapInit(e:Event):void
		{
			addChild(p);
			p.x=300;
			p.y=300;
			p.pos=new Point(p.x,p.y);
			addListener();
		}
		
		private function addListener():void
		{
			addEventListener(Event.ENTER_FRAME,onEnterFrame);
			stage.addEventListener(MouseEvent.CLICK,onStageClick);
		}
		
		private function onStageClick(e:MouseEvent):void
		{
			var po:Point=new Point(stage.mouseX,stage.mouseY);
			walkAction.executePoint(p,po,false);
		}
		
		private function onEnterFrame(e:Event):void
		{
			
		}
	}
}